<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/6/27
 * Time: 17:37
 */

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
class RecordTransferAccounts extends Model
{
    /**
     * 转账记录表
     * @var string
     */
    protected $table = 'record_transfer_accounts';
    protected $fillable = [
        'id' ,
        'uid',
        'tid',
        'user_name',
        'type',
        'money',
        'transfer',
        'nickname',
        'remark',
        'time',
    ];
    /**
     * 添加转账记录记录
     * @param array $order
     * @return bool|int 返回id
     */
    public function add_transfer($order = array())
    {
        if(empty($order)){
            return false;
        }
        $rico = $this->insertGetId($order);
        if ($rico) {
            return $rico;
        } else {
            return false;
        }
    }
    /**
     * 获取
     * @param array $where 条件
     * @param bool $limit 查询多少条
     * @param bool $pag 是否分页
     * @return array|bool
     */
    public function get_transfer($where = array(),$limit = null , $pag = null)
    {
        $table = $this->where($where)->orderBy('id','desc');
        if ($limit) {
            $table->limit($limit);
        }
        if( $pag ){
            $rico = $table->paginate(5);
        } else {
            $rico = $table->get();
        }
        if ($rico) {
            return $rico;
        } else {
            return false;
        }
    }
}